/*
Navicat MySQL Data Transfer

Source Server         : localhost
Source Server Version : 50137
Source Host           : localhost:3306
Source Database       : dail_db

Target Server Type    : MYSQL
Target Server Version : 50137
File Encoding         : 65001

Date: 2011-01-06 01:17:27
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `account_tbl`
-- ----------------------------
DROP TABLE IF EXISTS `account_tbl`;
CREATE TABLE `account_tbl` (
  `id` int(5) NOT NULL AUTO_INCREMENT,
  `username` text,
  `password` text,
  `email` text,
  `authority` int(4) DEFAULT NULL,
  `status` text,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records of account_tbl
-- ----------------------------

-- ----------------------------
-- Table structure for `character_tbl`
-- ----------------------------
DROP TABLE IF EXISTS `character_tbl`;
CREATE TABLE `character_tbl` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) DEFAULT NULL,
  `cluster_id` int(11) DEFAULT NULL,
  `name` text,
  `slot` int(11) DEFAULT NULL,
  `map_id` int(11) DEFAULT NULL,
  `hair_id` int(11) DEFAULT NULL,
  `hair_color` int(11) DEFAULT NULL,
  `face_id` int(11) DEFAULT NULL,
  `gender` int(11) DEFAULT NULL,
  `class` int(11) DEFAULT NULL,
  `level` int(11) DEFAULT NULL,
  `experience` bigint(20) DEFAULT NULL,
  `stat_points` int(11) DEFAULT NULL,
  `skill_points` int(11) DEFAULT NULL,
  `money` int(11) DEFAULT NULL,
  `strength` int(11) DEFAULT NULL,
  `stamina` int(11) DEFAULT NULL,
  `dexterity` int(11) DEFAULT NULL,
  `intelligence` int(11) DEFAULT NULL,
  `pos_x` float DEFAULT NULL,
  `pos_y` float DEFAULT NULL,
  `pos_z` float DEFAULT NULL,
  `hp` int(11) DEFAULT NULL,
  `mp` int(11) DEFAULT NULL,
  `fp` int(11) DEFAULT NULL,
  `fly_level` int(11) DEFAULT NULL,
  `fly_experience` int(11) DEFAULT NULL,
  `pvp` int(11) DEFAULT NULL,
  `pk` int(11) DEFAULT NULL,
  `disposition` int(11) DEFAULT NULL,
  `party` int(11) DEFAULT NULL,
  `guild` int(11) DEFAULT NULL,
  `pxp1` int(11) DEFAULT NULL,
  `pxp2` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records of character_tbl
-- ----------------------------

-- ----------------------------
-- Table structure for `item_tbl`
-- ----------------------------
DROP TABLE IF EXISTS `item_tbl`;
CREATE TABLE `item_tbl` (
  `character_id` int(11) DEFAULT NULL,
  `item_slot` int(11) DEFAULT NULL,
  `item_id` int(11) DEFAULT NULL,
  `quantity` int(11) DEFAULT NULL,
  `refine` int(11) DEFAULT NULL,
  `element` int(11) DEFAULT NULL,
  `element_refine` int(11) DEFAULT NULL,
  `bonuses` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records of item_tbl
-- ----------------------------

-- ----------------------------
-- Table structure for `server_tbl`
-- ----------------------------
DROP TABLE IF EXISTS `server_tbl`;
CREATE TABLE `server_tbl` (
  `parent_id` int(11) DEFAULT NULL,
  `id` int(11) DEFAULT NULL,
  `name` text,
  `ip` text,
  `enabled` int(11) DEFAULT NULL,
  `online_limit` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records of server_tbl
-- ----------------------------

-- ----------------------------
-- Function structure for `character_create_str`
-- ----------------------------
DROP FUNCTION IF EXISTS `character_create_str`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `character_create_str`(`CharacterID` int,`Gender` int) RETURNS int(11)
BEGIN
	IF Gender = 0 THEN
		INSERT INTO item_tbl(character_id, item_slot, item_id, quantity) VALUES(CharacterID, 44, 502, 1);
		INSERT INTO item_tbl(character_id, item_slot, item_id, quantity) VALUES(CharacterID, 46, 506, 1);
		INSERT INTO item_tbl(character_id, item_slot, item_id, quantity) VALUES(CharacterID, 47, 510, 1);
	ELSE
		INSERT INTO item_tbl(character_id, item_slot, item_id, quantity) VALUES(CharacterID, 44, 504, 1);
		INSERT INTO item_tbl(character_id, item_slot, item_id, quantity) VALUES(CharacterID, 46, 508, 1);
		INSERT INTO item_tbl(character_id, item_slot, item_id, quantity) VALUES(CharacterID, 47, 512, 1);
	END IF;
	
	INSERT INTO item_tbl(character_id, item_slot, item_id, quantity) VALUES(CharacterID, 52, 21, 1);
	
	RETURN 1;
END;;
DELIMITER ;

-- ----------------------------
-- Function structure for `character_delete_str`
-- ----------------------------
DROP FUNCTION IF EXISTS `character_delete_str`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `character_delete_str`(`CharacterID` int) RETURNS int(11)
BEGIN
	DECLARE temp_id INT;
	SELECT id INTO temp_id FROM character_tbl WHERE id=CharacterID;
	
	IF temp_id != CharacterID THEN
		RETURN -1;
	END IF;
	
	DELETE FROM character_tbl WHERE id=CharacterID;
	DELETE FROM item_tbl WHERE character_id=CharacterID;
	
	RETURN 1;
END;;
DELIMITER ;
